﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using RaytracerLib.Postprocessing;
using System.ComponentModel;
using RaytracerLib.Resamplers;
using System.Drawing.Drawing2D;
using RaytracerLib.Resamplers.Filters;

namespace Raytracer.PropertyGridDecorators
{
    public abstract class ResamplerProperties
    {
        private Resampler m_resampler;

        public ResamplerProperties(Resampler a_resampler)
        {
            m_resampler = a_resampler;
        }
    }

    public class NetResizerResamplerProperties : ResamplerProperties
    {
        private NetResizerResampler m_net_resizer_resampler;

        public NetResizerResamplerProperties(NetResizerResampler a_net_resizer_resampler)
            : base(a_net_resizer_resampler)
        {
            m_net_resizer_resampler = a_net_resizer_resampler;
        }

        public InterpolationMode Filter
        {
            get
            {
                return m_net_resizer_resampler.InterpolationMode;
            }
            set
            {
                m_net_resizer_resampler.InterpolationMode = value;
            }
        }
    }

    public class FilterResamplerProperties : ResamplerProperties
    {
        private FilterResampler m_filter_resampler;

        public FilterResamplerProperties(FilterResampler a_filter_resampler)
            : base(a_filter_resampler)
        {
            m_filter_resampler = a_filter_resampler;
        }

        [TypeConverter(typeof(FilterConverter))]
        public FilterProperties Filter
        {
            get
            {
                if (m_filter_resampler.Filter is BicubicFilter)
                    return new BicubicFilterProperties(m_filter_resampler.Filter as BicubicFilter);
                else if (m_filter_resampler.Filter is LanczosFilter)
                    return new LanczosFilterProperties(m_filter_resampler.Filter as LanczosFilter);
                else if (m_filter_resampler.Filter is MitchellFilter)
                    return new MitchellFilterProperties(m_filter_resampler.Filter as MitchellFilter);
                else if (m_filter_resampler.Filter is GaussianFilter)
                    return new GaussianFilterProperties(m_filter_resampler.Filter as GaussianFilter);
                else
                    return new FilterProperties(m_filter_resampler.Filter);
            }
        }

        [DisplayName("Filter type")]
        public FilterType FilterType
        {
            get
            {
                return m_filter_resampler.Filter.FilterType;
            }
            set
            {
                m_filter_resampler.Filter = RaytracerLib.Resamplers.Filters.Filter.Create(value);
            }
        }
    }

    public class LocalGridResamplerProperties : FilterResamplerProperties
    {
        private LocalGridResampler m_resampler;

        public LocalGridResamplerProperties(LocalGridResampler a_resampler)
            : base(a_resampler)
        {
            m_resampler = a_resampler;
        }

        public int Subresolution
        {
            get
            {
                return m_resampler.Subresolution;
            }
            set
            {
                m_resampler.Subresolution = value;
            }
        }
    }
}
